package com.ece.devirtualizus.Dao;

import java.io.File;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class SqlLiteGpsPositionHelper extends SQLiteOpenHelper {
	Context context;

	public SqlLiteGpsPositionHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		this.context = context;

	}

	private static final String DATABASE_NAME = "gpsposition1.db";
	private static final int DATABASE_VERSION = 1;

	public static final String TABLE_GPS_POSITION = "position";

	public static final String COLUMN_ID = "position_id";
	public static final String COLUMN_LAT = "latitude";
	public static final String COLUMN_LONG = "longitude";
	public static final String COLUMN_DATE = "date_creation";

	private static final String DATABASE_CREATE = "create table IF NOT EXISTS "
			+ TABLE_GPS_POSITION + "(" + COLUMN_ID
			+ " integer primary key autoincrement, " + COLUMN_LAT
			+ " REAL not null, " + COLUMN_LONG + " REAL not null, "
			+ COLUMN_DATE + " TEXT not null);";

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL(DATABASE_CREATE);
		Log.i("DATABASE_CREATE", "");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_GPS_POSITION + ";");
		Log.i("onUpgrade", "DROP TABLE IF EXISTS " + TABLE_GPS_POSITION + ";");

		onCreate(db);
	}

	public void destroyDatabase(SQLiteDatabase db) {
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_GPS_POSITION + ";");
		Log.i("onUpgrade", "DROP TABLE IF EXISTS " + TABLE_GPS_POSITION + ";");

	}

	public boolean checkDataBase() {
		File dbFile = context.getDatabasePath("/data/data/com.ece.devirtualizus/databases/gpsposition1.db");
		return dbFile.exists();
	}

	public void truncateDatabase(SQLiteDatabase db) {
		// db.execSQL("DELETE IF EXISTS FROM " + TABLE_GPS_POSITION+";");
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_GPS_POSITION + ";");
		db.execSQL(DATABASE_CREATE);
	}

}
